﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admincp_login : AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private bool Authentication()
    {
        try
        {
            GiaoVien giaovien = db.GiaoViens.Single(gv => gv.MaGiaoVien == txtUsername.Text);
            if (giaovien != null && Security.DecryptString(giaovien.MatKhau, this.Passphrase) == txtPassword.Text)
            {
                Employee = giaovien;
                return true;
            }
            else
                return false;
        }
        catch
        {
            return false;
        }
    }

    protected void CheckLogin(object sender, EventArgs e)
    {

        if (Authentication())
        {
            if (Session["ReturnUrl"] != null)
            {
                Response.Redirect(Session["ReturnUrl"].ToString());
            }
            else
            {
                Response.Redirect("dashboard.aspx");
            }
        }
        else
        {
            Response.Redirect("login.aspx");
        }

    }
}